﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;

namespace Alimentador.RightGroup.Patient
{
    /// <summary>
    /// Interaction logic for LoadPatientListPopUp.xaml
    /// </summary>
    public partial class LoadPatientListPopUp : Window
    {
        public LoadPatientListPopUp()
        {
            InitializeComponent();

            IEnumerable<string> patientlistPath = System.IO.Directory.EnumerateFiles(MainWindow.ProfileDirectory);

            List<string> patientList_str = new List<string>();
            foreach (string str in patientlistPath)
            {
                string FileName = str.Replace(MainWindow.ProfileDirectory, "");
                FileName = FileName.Replace(MainWindow.PERSON_DATA_FILE_EXTENSION, "");
                patientList_str.Add(FileName);
            }

            PatientList.ItemsSource = patientList_str;
        }

        internal string getSelectedPatient()
        {
            if (PatientList.SelectedIndex != -1)
            {
                return (string)PatientList.SelectedItem;
            }
            return "";
        }

        private void OpenBtn_Click(object sender, RoutedEventArgs e)
        {
            if (PatientList.SelectedIndex != -1)
            {
                Close();
            }
            else 
            {
                MessageBox.Show("Escolha primeiro qual o paciente que deseja abrir.", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            PatientList.SelectedIndex = -1;
            Close();
        }

        private void HandleDoubleClick(object sender, RoutedEventArgs e)
        {
            if(PatientList.SelectedIndex != -1)
                Close();
        }
    }
}